package com.example.adms.businessTrip.controller;


import com.example.adms.businessTrip.dto.*;
import com.example.adms.businessTrip.service.BusinessTripService;
import com.example.adms.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hyt
 * @since 2023-04-24
 */
@RestController
@RequestMapping("/businessTrip")
public class BusinessTripController {

    @Autowired
    BusinessTripService businessTripService;

    @PostMapping("/addBusinessTrip")
    public Result addLeave(@RequestBody BusinessTripMsg msg) {
        int flag = businessTripService.addBusinessTrip(msg);
        if (flag!=0){
            return Result.success("插入成功");
        }
        else {
            return Result.fail(501,"插入失败");
        }
    }

    @PostMapping("/getBusinessTripList")
    public Result getLeaveList(@RequestBody QueryBusinessTrip queryBusinessTrip){
        Map<String,Object> map = businessTripService.getBusinessTripList(queryBusinessTrip);
        return Result.success(map);
    }

    @PostMapping("/leaderGetBusinessTripList")
    public Result leaderGetLeaveList(@RequestBody QueryBusinessTrip queryBusinessTrip){
        Map<String,Object> map = businessTripService.leaderGetLeaveList(queryBusinessTrip);
        return Result.success(map);
    }

    @PostMapping("/employeeGetBusinessTripList")
    public Result employeeGetBusinessTripList(@RequestBody QueryBusinessTrip queryBusinessTrip){
        Map<String,Object> map = businessTripService.employeeGetBusinessTripList(queryBusinessTrip);
        return Result.success(map);
    }

    @PostMapping("/examineBusinessTrip")
    public Result examineBusinessTrip(@RequestBody ExamineBusinessTrip examineBusinessTrip){
        boolean result = businessTripService.examineBusinessTrip(examineBusinessTrip);
        if (result){
            return Result.success(null);
        }
        else {
            return Result.fail(501,"审批失败");
        }
    }

    @GetMapping("/deleteBusinessTrip")
    public Result deleteBusinessTrip(int businessTripId){
        boolean result = businessTripService.deleteBusinessTrip(businessTripId);
        if (result){
            return Result.success(null);
        }
        else {
            return Result.fail(501,"删除失败");
        }
    }

    @PostMapping("/businessTripReport")
    public Result businessTripReport(@RequestBody businessTripReport report){
        List<Object> list = businessTripService.businessTripReport(report);
        return Result.success(list);

    }
}
